#include <iostream>
#include <ctime>
#include <fstream>
#include <cstring>
using namespace std;

void bubbleSort (int nums[], int numsLenght)
{
    while(numsLenght)
    {
        bool swapped = false;
        for(int i = 0; i < numsLenght; i++)
        {
            if(nums[i] > nums[i + 1])
            {
                swap(nums[i], nums[i + 1]);
                swapped = true;
            }
        }
       if(swapped == false) break;
    }
}

void read_from_file(const char *filename, int a[], int lenght)
{
    ifstream file(filename);

    for(int j=0; j < lenght; j++)
        file >> a[j];
}

int main()
{
    #define LEN 5000
    int a[LEN];

    read_from_file("m1_sorted.txt", a, LEN);
    unsigned int t_start = clock();
    bubbleSort (a, LEN);
    unsigned int t_finish = clock();
    unsigned int t_work = t_finish - t_start;
    cout<<"  m1_sorted " << t_work << " milliseconds \n";

    read_from_file("m2_reverse.txt", a, LEN);
    unsigned int t_start2 = clock();
    bubbleSort (a, LEN);
    unsigned int t_finish2 = clock();
    unsigned int t_work2 = t_finish2 - t_start2;
    cout<<"  m2_reverse " << t_work2 << " milliseconds \n";

    read_from_file("m3_shuffle.txt", a, LEN);
    unsigned int t_start3 = clock();
    bubbleSort (a, LEN);
    unsigned int t_finish3 = clock();
    unsigned int t_work3 = t_finish3 - t_start3;
    cout<<"  m3_shuffle " << t_work3 << " milliseconds \n";
}
